<template>
  <div class="app-container">


      <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign" style="width: 300px">
        <!-- <el-form-item label="公式">
            <el-input v-model="formLabelAlign.name"></el-input>
        </el-form-item> -->
        <el-form-item label="x的值">
            <el-input v-model="formLabelAlign.x"></el-input>
        </el-form-item>
        
        </el-form>

     


    <!--表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-button
        :disabled="btnDisabled"
        type="primary"
        icon="el-icon-search"
        @click="showChart()">查询</el-button>
    </el-form>
    



    <div class="chart-container">       
      <div id="chart" class="chart" style="height:1000px;width:100%" />
    </div>
  </div>
</template>
<script>
//import echarts from 'echarts'
import * as echarts from 'echarts';


export default {
    data() {
        return {
            formLabelAlign:{
                
                x:''
            }
            
        }
    },
    created(){
        
          

      },

    methods:{
        showChart(){
           this.setChart()
        },
    
        setChart() {
            // 基于准备好的dom，初始化echarts实例
            this.chart = echarts.init(document.getElementById('chart'))
             console.log(this.formLabelAlign.x)



            function func(x) {
                x /= 10;
                return Math.sin(x) * Math.cos(x * 2 + 1) * Math.cos(x * 3 + 2)*50 ;
                //return this.formLabelAlign.x;
                
            }

            function generateData() {
                let data = [];
                for (let i = -300; i <= 300; i += 0.1) {
                    data.push([i, func(i)]);
                }
                return data;
            }

            
            // 指定图表的配置项和数据
            var option = {
                animation: false,
                grid: {
                    top: 40,
                    left: 50,
                    right: 40,
                    bottom: 50
                },
                xAxis: {
                    name: 'x',
                    minorTick: {
                        show: true
                    },
                    minorSplitLine: {
                        show: true
                    }
                },
                yAxis: {
                    name: 'y',
                    min: -100,
                    max: 100,
                    minorTick: {
                        show: true
                    },
                    minorSplitLine: {
                        show: true
                    }
                },
                dataZoom: [{
                    show: true,
                    type: 'inside',
                    filterMode: 'none',
                    xAxisIndex: [0],
                    startValue: -20,
                    endValue: 20
                }, {
                    show: true,
                    type: 'inside',
                    filterMode: 'none',
                    yAxisIndex: [0],
                    startValue: -20,
                    endValue: 20
                }],
                series: [
                    {
                        type: 'line',
                        showSymbol: false,
                        clip: true,
                        data: generateData()
                    }
                ]
            };

                    

            this.chart.setOption(option)
        }
    }
}
</script>
